class Observer {
  constructor(data) {
    this.walk(data)
  }
  walk(data) {
    Object.keys(data).forEach((key) => {
      defineReactive(data, key, data[key])
    })
  }
}
export function defineReactive(target, key, value) {
  observer(value)
  Object.defineProperty(target, key, {
    get() {
      return value
    },
    set(newValue) {
      if (newValue == value) {
        return
      }
      observer(newValue)
      value = newValue
    },
  })
}
export function observer(data) {
  if (typeof data !== 'object' || !data) {
    return
  }
  return new Observer(data)
}
